package com.fly.video.downloader.core.app;


/**
 * Class to manage status and navigation bar tint effects when using KitKat
 * translucent system UI modes.
 *
 */
public class SystemBarTintManager {

    /**
     * The default system bar tint color value.
     */
    public static final int DEFAULT_TINT_COLOR = 0x99000000;

//    private final SystemBarMetrics mConfig;
//    private boolean mStatusBarAvailable;
//    private boolean mNavBarAvailable;
//    private boolean mStatusBarTintEnabled;
//    private boolean mNavBarTintEnabled;
//    private View mStatusBarTintView;
//    private View mNavBarTintView;

    /**
     * Constructor. Call this in the host activity onCreate method after its
     * content view has been set. You should always create new instances when
     * the host activity is recreated.
     *
     * @param activity The host activity.
     */
//    @TargetApi(19)
//    public SystemBarTintManager(Activity activity) {
//
//        Window win = activity.getWindow();
//        ViewGroup decorViewGroup = (ViewGroup) win.getDecorView();
//
//        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
//            // check theme attrs
//            int[] attrs = {android.R.attr.windowTranslucentStatus,
//                    android.R.attr.windowTranslucentNavigation};
//            TypedArray a = activity.obtainStyledAttributes(attrs);
//            try {
//                mStatusBarAvailable = a.getBoolean(0, false);
//                mNavBarAvailable = a.getBoolean(1, false);
//            } finally {
//                a.recycle();
//            }
//
//            // check window flags
//            WindowManager.LayoutParams winParams = win.getAttributes();
//            int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
//            if ((winParams.flags & bits) != 0) {
//                mStatusBarAvailable = true;
//            }
//            bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION;
//            if ((winParams.flags & bits) != 0) {
//                mNavBarAvailable = true;
//            }
//        }
//
//        mConfig = new SystemBarMetrics(activity, mStatusBarAvailable, mNavBarAvailable);
//        // device might not have virtual navigation keys
//        if (!mConfig.hasNavigtionBar()) {
//            mNavBarAvailable = false;
//        }
//
//        if (mStatusBarAvailable) {
//            setupStatusBarView(activity, decorViewGroup);
//        }
//        if (mNavBarAvailable) {
//            setupNavBarView(activity, decorViewGroup);
//        }
//
//    }

    /**
     * Enable tinting of the system status bar.
     * <p>
     * If the platform is running Jelly Bean or earlier, or translucent system
     * UI modes have not been enabled in either the theme or via window flags,
     * then this method does nothing.
     *
     * @param enabled True to enable tinting, false to disable it (default).
     */
//    public void setStatusBarTintEnabled(boolean enabled) {
//        mStatusBarTintEnabled = enabled;
//        if (mStatusBarAvailable) {
//            mStatusBarTintView.setVisibility(enabled ? View.VISIBLE : View.GONE);
//        }
//    }

    /**
     * Enable tinting of the system navigation bar.
     * <p>
     * If the platform does not have soft navigation keys, is running Jelly Bean
     * or earlier, or translucent system UI modes have not been enabled in either
     * the theme or via window flags, then this method does nothing.
     *
     * @param enabled True to enable tinting, false to disable it (default).
     */
//    public void setNavigationBarTintEnabled(boolean enabled) {
//        mNavBarTintEnabled = enabled;
//        if (mNavBarAvailable) {
//            mNavBarTintView.setVisibility(enabled ? View.VISIBLE : View.GONE);
//        }
//    }

    /**
     * Apply the specified color tint to all system UI bars.
     *
     * @param color The color of the background tint.
     */
//    public void setTintColor(int color) {
//        setStatusBarTintColor(color);
//        setNavigationBarTintColor(color);
//    }

    /**
     * Apply the specified drawable or color resource to all system UI bars.
     *
     * @param res The identifier of the resource.
     */
//    public void setTintResource(int res) {
//        setStatusBarTintResource(res);
//        setNavigationBarTintResource(res);
//    }

    /**
     * Apply the specified drawable to all system UI bars.
     *
     * @param drawable The drawable to use as the background, or null to remove it.
     */
//    public void setTintDrawable(Drawable drawable) {
//        setStatusBarTintDrawable(drawable);
//        setNavigationBarTintDrawable(drawable);
//    }

    /**
     * Apply the specified alpha to all system UI bars.
     *
     * @param alpha The alpha to use
     */
//    public void setTintAlpha(float alpha) {
//        setStatusBarAlpha(alpha);
//        setNavigationBarAlpha(alpha);
//    }

    /**
     * Apply the specified color tint to the system status bar.
     *
     * @param color The color of the background tint.
     */
//    public void setStatusBarTintColor(int color) {
//        if (mStatusBarAvailable) {
//            mStatusBarTintView.setBackgroundColor(color);
//        }
//    }

    /**
     * Apply the specified drawable or color resource to the system status bar.
     *
     * @param res The identifier of the resource.
     */
//    public void setStatusBarTintResource(int res) {
//        if (mStatusBarAvailable) {
//            mStatusBarTintView.setBackgroundResource(res);
//        }
//    }

    /**
     * Apply the specified drawable to the system status bar.
     *
     */
//    @SuppressWarnings("deprecation")
//    public void setStatusBarTintDrawable(Drawable drawable) {
//        if (mStatusBarAvailable) {
//            mStatusBarTintView.setBackgroundDrawable(drawable);
//        }
//    }

    /**
     * Apply the specified alpha to the system status bar.
     *
     * @param alpha The alpha to use
     */
//    @TargetApi(11)
//    public void setStatusBarAlpha(float alpha) {
//        if (mStatusBarAvailable && Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
//            mStatusBarTintView.setAlpha(alpha);
//        }
//    }

    /**
     * Apply the specified color tint to the system navigation bar.
     *
     * @param color The color of the background tint.
     */
//    public void setNavigationBarTintColor(int color) {
//        if (mNavBarAvailable) {
//            mNavBarTintView.setBackgroundColor(color);
//        }
//    }

    /**
     * Apply the specified drawable or color resource to the system navigation bar.
     *
     * @param res The identifier of the resource.
     */
//    public void setNavigationBarTintResource(int res) {
//        if (mNavBarAvailable) {
//            mNavBarTintView.setBackgroundResource(res);
//        }
//    }

    /**
     * Apply the specified drawable to the system navigation bar.
     *
//     * @param drawable The drawable to use as the background, or null to remove it.
     */
//    @SuppressWarnings("deprecation")
//    public void setNavigationBarTintDrawable(Drawable drawable) {
//        if (mNavBarAvailable) {
//            mNavBarTintView.setBackgroundDrawable(drawable);
//        }
//    }

    /**
     * Apply the specified alpha to the system navigation bar.
     *
     * @param alpha The alpha to use
     */
//    @TargetApi(11)
//    public void setNavigationBarAlpha(float alpha) {
//        if (mNavBarAvailable && Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
//            mNavBarTintView.setAlpha(alpha);
//        }
//    }

    /**
     * Get the system bar configuration.
     *
     * @return The system bar configuration for the current device configuration.
     */
//    public SystemBarMetrics getConfig() {
//        return mConfig;
//    }

    /**
     * Is tinting enabled for the system status bar?
     *
     * @return True if enabled, False otherwise.
     */
//    public boolean isStatusBarTintEnabled() {
//        return mStatusBarTintEnabled;
//    }

    /**
     * Is tinting enabled for the system navigation bar?
     *
     * @return True if enabled, False otherwise.
     */
//    public boolean isNavBarTintEnabled() {
//        return mNavBarTintEnabled;
//    }

//    private void setupStatusBarView(Context context, ViewGroup decorViewGroup) {
//        mStatusBarTintView = new View(context);
//        LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, mConfig.getStatusBarHeight());
//        params.gravity = Gravity.TOP;
//        if (mNavBarAvailable && !mConfig.isNavigationAtBottom()) {
//            params.rightMargin = mConfig.getNavigationBarWidth();
//        }
//        mStatusBarTintView.setLayoutParams(params);
//        mStatusBarTintView.setBackgroundColor(DEFAULT_TINT_COLOR);
//        mStatusBarTintView.setVisibility(View.GONE);
//        decorViewGroup.addView(mStatusBarTintView);
//    }
//
//    private void setupNavBarView(Context context, ViewGroup decorViewGroup) {
//        mNavBarTintView = new View(context);
//        LayoutParams params;
//        if (mConfig.isNavigationAtBottom()) {
//            params = new LayoutParams(LayoutParams.MATCH_PARENT, mConfig.getNavigationBarHeight());
//            params.gravity = Gravity.BOTTOM;
//        } else {
//            params = new LayoutParams(mConfig.getNavigationBarWidth(), LayoutParams.MATCH_PARENT);
//            params.gravity = Gravity.RIGHT;
//        }
//        mNavBarTintView.setLayoutParams(params);
//        mNavBarTintView.setBackgroundColor(DEFAULT_TINT_COLOR);
//        mNavBarTintView.setVisibility(View.GONE);
//        decorViewGroup.addView(mNavBarTintView);
//    }

}